﻿<?php
	class users
	{

	var $username,$password,$fullname,$email,$tel,$avatar;		// Khai bao cac thuoc tinh

	function users() //Khai bao gia tri cho cac thuoc tinh, o day se gan gia tri rong
		{
			$this->username="";  // ham tao khong co tham so truyen vao
			$this->password='';
			$this->fullname="";
			$this->email="";
			$this->tel="";
			$this->avatar="";
		}
		/*
	function user($username='',$password='',$fullname='',$email='',$tel='',$avatar='')  // Ham tao co tham so truyen vao, gan mac dinh bang rong, neu khong co gia tri se lay gia tri mang dinh (= rong)
		//Dau nhay su dung nhay '' hay "" deu duoc
		{
			$this->username="";   // Ham tao thu 2, co tham so truyen vao
			$this->password="";
			$this->fullname="";
			$this->email="";
			$this->tel="";
			$this->avatar="";

		}
		*/
	function save () // ham save thanh file . luu tat ca noi dung user thanh file
		{
			if(!$this->is_exists())
			{
				$SQL ="INSERT INTO users(username,password,email,fullname,tel,status) VALUES ('".$this->username."','".$this->password."','".$this->email."','".$this->fullname."','".$this->tel."',1)";
				$rs=mysql_query($SQL);
				if($rs) {
					echo ("Dang ky thanh cong");
					return true; // Đăng ký thành công

						}
				else	{
				echo ("Thanh vien da ton tai");
				return false; // Đăng ký ko thành công
						}
			}
				echo ("Thanh vien da ton tai");
				return false;

		}
	function get($username)
		{
			$nd=file_get_contents($username.".txt");
			$u=unserialize($nd);
			$this->username=$u->username;
			$this->password=$u->password;
			$this->email=$u->email;
			$this->tel=$u->tel;
			$this->fullname=$u->fullname;
			$this->avatar=$u->avatar;
			unset($u);
			unset($nd);
		}
	function is_exists()
		{
			$SQL="SELECT * FROM users WHERE username='".$this->username."'";
			$rs=mysql_query($SQL);
			// Lay so ban ghi tra ve thong qua  ham $count=mysql_num_rows($rd); trả về số bản ghi thực hiện câu lệnh này. nếu cout<0 tức là đã tồn tại thành viên đó
			if($rs) {
				$count=mysql_num_rows($rs);
				if($count>0) return true;
					}
			else {
			 return false;
				}

		}

}

function vn_str_filter ($str){

       $unicode = array(

           'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',

           'd'=>'đ',

           'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',

           'i'=>'í|ì|ỉ|ĩ|ị',

           'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',

           'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',

           'y'=>'ý|ỳ|ỷ|ỹ|ỵ',

           'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',

           'D'=>'Đ',

           'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',

           'I'=>'Í|Ì|Ỉ|Ĩ|Ị',

           'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',

           'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',

           'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',

       );

      foreach($unicode as $nonUnicode=>$uni){

           $str = preg_replace("/($uni)/i", $nonUnicode, $str);

      }

       return $str;

   }

?>
